package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.impl.ActivityServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
@SuppressWarnings("all")
public class ActivityController {
    @Autowired
    private ActivityServiceImpl activityService;

    @GetMapping
    public Result page(
            @RequestParam(name = "channel", required = false) Integer channel,
            @RequestParam(name = "type", required = false) Integer type,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize){
         PageResult<Activity> PageResult= activityService.page(channel, type, status, page, pageSize);
         log.info("分页查询活动,参数:渠道来源={},活动类型={},活动状态={},当前页码={},每页大小={}", channel, type, status, page, pageSize);
         return Result.success(PageResult);
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        log.info("添加活动信息:{}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }
    @GetMapping("/{id}")
        public Result selectId(@PathVariable("id") Integer id){
        log.info("查询活动id为：{}",id);
        Activity activity =activityService.selectId(id);
        return Result.success(activity);
    }
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        log.info("修改活动信息为：{}",activity);
        activityService.updateActivity(activity);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable Integer id){
        log.info("删除活动id为：{}",id);
        activityService.deleteActivity(id);
        return Result.success();
    }
    @GetMapping("/type/{type}")
    public Result selectType(@PathVariable Integer type){
        log.info("查询活动类型为：{}",type);
        return Result.success(activityService.selectType(type));
    }

}
